-
-
Notifications
You must be signed in to change notification settings - Fork 195
Sheffield | May-2025 | WALEED-YAHYA SALIH-TAHA | Sprint-3 #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2. identified obtuse angle and it's function 3. identified stright angle and it's function 4. identified reflex anglewith it's function.
2. Identified Obtuse angles when it's greater than 90 degrees and less than 180, and added a line to test the function. 3. added a line to test all the if conditions in the program.
…odule-Structuring-and-Testing-Data into Sprint3-Test-branch
… line code to check the result.
…o it to handle diffrent type of the cards.
…odule-Structuring-and-Testing-Data into Sprint3-Test-branch
2. tested other scenarios like Zero numerator
…mplement. 2. Added some test examples.
2. handled Ace (A)
… a positive integer count.
…odule-Structuring-and-Testing-Data into Sprint3-Test-branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sprint-3/4-stretch-investigate/password-validator.js
Sprint-3/4-stretch-investigate/password-validator.test.js
I noticed the code in the above two files were partially modified buy they are not yet fully implemented. Since "stretch" exercises are optional, I will only comment when they are fully implemented.
console.log(getAngleType(90)); // Right angle | ||
console.log(getAngleType(135)); // Obtuse angle | ||
console.log(getAngleType(180)); // Straight angle | ||
console.log(getAngleType(270)); // Reflex angle | ||
console.log(getAngleType(0)); // Invalid angle | ||
console.log(getAngleType(360)); // Invalid angle | ||
console.log(getAngleType(-10)); // Invalid angle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused code or code used solely for development purposes should be removed or, at the very least, commented out with clear justification.
const zeroNumerator = isProperFraction(0, 5); | ||
assertEquals(zeroNumerator, true); // ✅ should pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically 0 is not considered a proper fraction. :)
const rank = card.slice(0, -1); // Get the rank (everything except the last character) | ||
if (rank === "A") return 11; | ||
if (["J", "Q", "K"].includes(rank)) return 10; | ||
if (rank >= "2" && rank <= "9") return parseInt(rank, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings are compared differently in the JS language.
Does your function return the value you expected from each of the following function calls?
getCardValue("333♠");
getCardValue("3.1416♠");
getCardValue("3ABC♠");
test("should return 5 for 5 of Hearts", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.
For example, one possible category for getCardValue()
is, "should return the value of number cards (2-10)", and we can prepare the test as
test("should return the value of number cards (2-10)", () => {
expect(getCardValue("2♣︎")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♥")).toEqual(5);
// Note: We could also use a loop to check all values from 2 to 10.
});
test("should return 10 for Jack of Diamonds", () => { | ||
const jackOfDiamonds = getCardValue("J♦"); | ||
expect(jackOfDiamonds).toEqual(10); | ||
}); | ||
test("should return 10 for Queen of Clubs", () => { | ||
const queenOfClubs = getCardValue("Q♣"); | ||
expect(queenOfClubs).toEqual(10); | ||
}); | ||
test("should return 10 for King of Spades", () => { | ||
const kingOfSpades = getCardValue("K♠"); | ||
expect(kingOfSpades).toEqual(10); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also combine these tests into one under the category "should return 10 for face cards (J, Q, K)".
function countChar(stringOfCharacters, findCharacter) { | ||
// Initialize a counter | ||
let count = 0; | ||
|
||
// Scenario: Multiple Occurrences | ||
// Given the input string str, | ||
// And a character char that may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'), | ||
// When the function is called with these inputs, | ||
// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa'). | ||
// Loop through the string | ||
for (let char of stringOfCharacters) { | ||
if (char === findCharacter) { | ||
count++; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why defined another countChar()
function in this script? The code in this script is supposed to test the function implemented in Sprint-3/3-mandatory-practice/implement/count.test.js
.
function getOrdinalNumber(num) { | ||
|
||
module.exports = getOrdinalNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statement module.exports = ...
should be placed outside of any function block; usually at the end of the file.
return "1st"; | ||
} else if (num === 2) { | ||
return "2nd"; | ||
} else if (num === 3) { | ||
return "3rd"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just rely on the code at lines 20-25 to handle these three specific numbers?
test("should return '2nd' for 2", () => { | ||
expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories. Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.
For example, we can prepare a test for numbers 2, 22, 132, etc. as
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect( getOrdinalNumber(2) ).toEqual("2nd");
expect( getOrdinalNumber(22) ).toEqual("22nd");
expect( getOrdinalNumber(132) ).toEqual("132nd");
});
Can you update the tests in this script so that they can cover all valid integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not delete the code at lines 1-3?
Learners, PR Template
Self checklist
Changelist
Sprint-3 is mainly about implementing, rewriting, practicing and and testing functions.
Questions
Ask any questions you have for your reviewer.